﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>飞羽体育</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
    <link href="https://cdn.bootcss.com/amazeui/2.7.2/css/amazeui.css" rel="stylesheet">
    <link href="http://s.amazeui.org/assets/2.x/css/amaze.min.css?v=ivneioml" rel="stylesheet" />
    <link href="css/common.css" rel="stylesheet" />
</head>
<body>
    <div id="page" v-cloak>
        <div v-show="showpage=='login'" id="login">
            <div id="header" style="text-align:center;">
                <img src="images/loginheader.jpg" style="width:100%;" />
                <form action="" class="am-form am-form-inline" style="padding-top:10px;">
                    <div class="am-u-sm-centered am-u-sm-11">
                        <div class="am-form-group am-form-icon" style=" margin-top: 20px; border-bottom: 1px solid #ccc;">
                            <i class="am-icon-mobile" style="color: #6FDDB1; font-size: 22px;"></i>
                            <input type="text" class="am-form-field" v-model="phone" style="border:none;" placeholder="请输入手机号">
                        </div>
                    </div>
                    <div class="am-u-sm-centered am-u-sm-11">
                        <div class="am-form-group am-form-icon" style=" margin-top: 20px; border-bottom: 1px solid #ccc;">
                            <i class="am-icon-lock" style="color: #6FDDB1;font-size:18px;"></i>
                            <input type="password" class="am-form-field" v-model="password" style="border:none;" placeholder="密码">
                        </div>
                    </div>
                    <div class="am-u-sm-centered am-u-sm-11">
                        <button type="button" v-on:click="login" class="am-btn am-btn-default am-btn-block am-btn-xl" style="background-color: #6FDDB1;color:#ffffff;">登录</button>
                    </div>
                    <div class="am-u-sm-centered am-u-sm-12" style="padding-top:10px;">
                        <div class="am-u-sm-6" style="text-align:left;">
                            <a href="javascript:void(0)" style="color: #555555;">忘记密码?</a>
                        </div>
                        <div class="am-u-sm-6" style="text-align: right;">
                            <a href="javascript:void(0)" v-on:click="showpage='register'" style="color: #6FDDB1">立即注册?</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div v-show="showpage=='register'" id="register">
            <div id="header" style="text-align:center;">
                <img src="images/loginheader.jpg" style="width:100%;" />
                <form action="" class="am-form am-form-inline">
                    <div class="am-u-sm-centered am-u-sm-11" style="padding-top:10px;">
                        <div class="am-form-group am-form-icon" style=" margin-top: 20px; border-bottom: 1px solid #ccc;">
                            <i class="am-icon-mobile" style="color: #6FDDB1; font-size: 22px;"></i>
                            <input type="text" class="am-form-field" v-model="phone" style="border:none;" placeholder="请输入手机号">
                        </div>
                    </div>
                    <div class="am-u-sm-centered am-u-sm-11">
                        <div class="am-form-group am-form-icon" style="margin-top: 20px; border-bottom: 1px solid #ccc;">
                            <i class="am-icon-mobile" style="color: #6FDDB1; font-size: 22px;"></i>
                            <input type="text" class="am-form-field" v-model="code" style="border:none;" placeholder="验证码">
                            <div v-on:click="sendCode" style="float: right; margin-top: -30px; color: #6FDDB1;">
                                获取验证码
                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-centered am-u-sm-11">
                        <div class="am-form-group am-form-icon" style=" margin-top: 20px; border-bottom: 1px solid #ccc;">
                            <i class="am-icon-shield" style="color: #6FDDB1;font-size:18px;"></i>
                            <input type="password" class="am-form-field" v-model="password" style="border:none;" placeholder="密码">
                        </div>
                    </div>
                    <div class="am-u-sm-centered am-u-sm-11">
                        <div class="am-form-group am-form-icon" style=" margin-top: 20px; border-bottom: 1px solid #ccc;">
                            <i class="am-icon-lock" style="color: #6FDDB1;font-size:18px;"></i>
                            <input type="password" class="am-form-field" v-model="confirmpassword" style="border:none;" placeholder="确认密码">
                        </div>
                    </div>
                    <div class="am-u-sm-centered am-u-sm-11">
                        <button type="button" v-on:click="register" class="am-btn am-btn-default am-btn-block am-btn-xl" style="background-color: #6FDDB1;color:#ffffff;">注册</button>
                    </div>
                    <div class="am-u-sm-centered am-u-sm-12" style="padding-top:20px;">
                        <i class=" am-icon-reply" style="color: #6FDDB1;font-size:18px;"></i>
                        <a href="javascript:void(0)" v-on:click="showpage='login'" style="color: #6FDDB1;">去登录</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html>
<script src="https://use.fontawesome.com/ca6b609d64.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.8.3/jquery.js"></script>
<script src="https://cdn.bootcss.com/vue/2.5.9/vue.js"></script>
<script src="https://cdn.bootcss.com/amazeui/2.7.2/js/amazeui.js"></script>
<script src="js/amazeui.dialog.js"></script>
<script type="text/javascript">
    var host = "http://feiyutiyu.cn";
    var page = new Vue({
        el: '#page',
        data: {
            showpage:"login",
            phone: "",
            password: "",
            code: "",
            codeId: "",
            confirmpassword: "",
            openid:"",
            nickname:"",
            sex:"",
            headimgurl:"",
            province:"",
            city:"",
            unionid: "",
            jsonstr:"",
        },
        methods: {
            login: function () {
                var that = this;
                $.ajax({
                    url: host+"/Api/Login",
                    data: {
                        phone: that.phone,
                        password: that.password,
                        openid: that.openid,
                        nickname: that.nickname,
                        sex: that.sex,
                        headimgurl: that.headimgurl,
                        province: that.province,
                        city: that.city,
                        unionid: that.unionid,
                        //jsonstr: that.jsonstr,
                    },
                    type: "POST",
                    success: function (data) {
                        if (data.errcode == 0) {
                            localStorage.setItem("token", data.data.token);
                            location.replace($.getParam("backurl") == null ? "venue.html" : $.getParam("backurl"));
                        }
                        else if (data.errcode == -1)
                            alert(data.errmsg);
                        else
                            console.log(data);
                    },
                    //error: function () {
                    //    alert("登录异常");
                    //}
                })
            },
            register: function () {
                var that = this;
                $.ajax({
                    url: host + "/Api/Register",
                    data: {
                        phone: that.phone,
                        password: that.password,
                        code: that.code,
                        codeId: that.codeId,
                        confirmpassword: that.confirmpassword,
                        openId: that.openId,
                        nickname: that.nickname,
                        sex: that.sex,
                        headimgurl: that.headimgurl,
                        province: that.province,
                        city: that.city,
                        unionid: that.unionid,
                    },
                    type: "POST",
                    success: function (data) {
                        if (data.errcode == 0) {
                            that.showpage = "login";
                            alert("注册成功");
                        }
                        else if (data.errcode == -1)
                            alert(data.errmsg);
                        else
                            console.log(data);
                    },
                    //error: function () {
                    //    alert("注册异常");
                    //}
                })
            },
            sendCode: function () {
                var that = this;
                $.ajax({
                    url: host + "/Api/Register/sendCode",
                    data: {
                        phone: that.phone
                    },
                    type: "POST",
                    success: function (data) {
                        if (data.errcode == 0) {
                            that.codeId = data.data.codeId;
                            alert("发送成功");
                        }
                        else if (data.errcode == -1)
                            alert(data.errmsg);
                        else
                            console.log(data);
                    },
                    //error: function () {
                    //    alert("发送失败");
                    //}
                })
            }
        },
        watch: {
            
        }
    })
    $.getParam = function (name) {
        var url = window.location.search;
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var result = url.substr(1).match(reg);
        return result ? decodeURIComponent(result[2]) : null;
    }
    $(function () {
        //page.openId = $.getParam("openId");
        //page.nickname = $.getParam("nickname");
        //alert(page.nickname);
        //page.sex = $.getParam("sex");
        //page.headimgurl = $.getParam("headimgurl");
        //page.province = $.getParam("province");
        //page.city = $.getParam("city");
        //page.unionid = $.getParam("unionid");
        //page.jsonstr = $.getParam("jsonstr");

        page.openid = $.getParam("openid");
        page.nickname = $.getParam("nickname");
        page.sex = $.getParam("sex");
        page.language = $.getParam("language");
        page.city = $.getParam("city");
        page.province = $.getParam("province");
        page.country = $.getParam("country");
        page.headimgurl = $.getParam("headimgurl");
        page.unionid = $.getParam("unionid");
    })

</script>